Kuo['apijson/admin_request'] = {
    LEIJIA: 0,
    url: plug + "apijson" + FENGE + "admin_request" + FENGE,
    YESNO: ["否", "是"],
    OFF: ["删除", "关闭", "开启"],
    $BIAODAN: {}, //表单
    $HANSHU: {}, //函数
    $method: { 'get': 'Get', 'put': 'Put', 'add': 'Add', 'del': 'Del', 'data': 'Data' },
    $grade: { "-1": "游客", "0": "普通用户", "88": "超级管理" },
    init: function () {
        Kuo['apijson/admin_request'].get();
        var xxx = '<option value="">全部状态</option>';
        for (var n in Kuo["apijson/admin_request"].OFF) {
            xxx += '<option value="' + n + '">' + Kuo["apijson/admin_request"].OFF[n] + '</option>';
        }
        $("." + $class + "saixuan [name='so_off']").html(xxx);
        layui.form.render("select");
    },
    edit(OBJ, diercai) {
        if (diercai != "add") {
            diercai = "put";
            var title = "编辑处理";
        } else {
            var title = "新建处理";
        }
        window.UIMUI = Array();
        var D = OBJ.data;
        var BIAO = [];
        var caifuw = function (data) {
            let zifuchuan = [];
            try {
                zifuchuan = JSON.parse(data);
            } catch (error) {

            }
            return zifuchuan.join(',');
        }
        var html = '<form name="form" id="form" class="layui-form ' + $class + '">';
        BIAO = [

            'id($$)id($$)hidden($$)($$)id($$)' + D.id,
            'tags($$)tag名称($$)text($$)($$)外部调用tag名称($$)' + D.tags,
            'method($$)Method($$)checkbox($$)($$)Kuo["apijson/admin_request"].$method($$)' + caifuw(D.method)

        ];


        for (var z in BIAO) {
            html += jsfrom(BIAO[z]);
        }
        let dstructure = [];
        try {
            dstructure = JSON.parse(D.structure);
        } catch (error) { }

        html += '<div class="XuaDan' + $class + '  layui-form-item"><label class="layui-form-label">参数配置</label><div class="layui-input-block" id="' + $class + 'x_structure">';

        html += `<table class="layui-table">
  <colgroup>
    <col>

    <col>
    <col width="158">
    <col>
    <col>
    <col width="100">
  </colgroup>
  <thead>
    <tr>
      <th>表单名</th>
      <th>字段名</th>
      <th>是否必填</th>
      <th>验证规则</th>
      <th>处理函数</th>
      <th>操作</th>
    </tr> 
  </thead>
  <tbody >`;


        for (let m in dstructure) {

            let tdata = dstructure[m];
            html += '<tr class="chulis' + m + '">';
            html += `<td><input type="text" class="layui-input" name="structure[` + m + `][n]" placeholder="表单名字"  value="` + tdata['n'] + `"></td>`;

            html += `<td><input type="text" class="layui-input" name="structure[` + m + `][z]" value="` + tdata['z'] + `" placeholder="数据库字段名可为空"></td>`;


            html += `<td><select name="structure[` + m + `][b]" >
                <option value="0" `+ (tdata['b'] == '0' ? ' selected ' : '') + `>选填</option>
                <option value="1" `+ (tdata['b'] == '1' ? ' selected ' : '') + `>必填</option></select></td>`;

            // html +=`<td><input type="text" class="layui-input" name="structure[`+m+`][b]"  value="`+tdata['b']+`"></td>`;


            html += `<td> <div><div class="layui-input-inline"  style="width:70%;"><input type="text" class="layui-input BIAODAN" name="structure[` + m + `][g]" placeholder="验证规则"  value="` + tdata['g'] + `"></div> <div class="layui-input-inline" style="width:0%;"> 
        <button type="button" class="layui-btn" onclick="Kuo['apijson/admin_request'].TABLEYANZHENG(`+ m + `)"  >选择验证</button></div></td>`;

            html += `<td> <div class="layui-inline"><div class="layui-input-inline " style="width:70%;"><input type="text" class="layui-input HANSHU" name="structure[` + m + `][c]" placeholder="函数处理"  value="` + tdata['c'] + `"></div> <div class="layui-input-inline" style="width:0%;"> 
        <button type="button" class="layui-btn  layui-bg-blue"  onclick="Kuo['apijson/admin_request'].TABLEHANSHU(`+ m + `)" >选择函数</button></div></td>`;



            html += `<td> <button type="button" onclick="Kuo['apijson/admin_request'].TABLEDEL(` + m + `)"  class="layui-btn layui-bg-red" >删除</button></td>`;

            html += '</tr>';

            Kuo['apijson/admin_request'].LEIJIA++;
        }
        Kuo['apijson/admin_request'].LEIJIA++;
        html += `</tbody></table>`;

        html += `<div><button type="button" onclick="Kuo['apijson/admin_request'].TABLEADD()"  class="layui-btn layui-bg-blue" >新增配置</button></div>`;

        html += '</div></div>';


        BIAO = [
            'atime($$)更改时间($$)time($$)($$)更改时间($$)' + D.atime,
            'off($$)开关($$)select($$)($$)Kuo["apijson/admin_request"].OFF($$)' + D.off,
            'detail($$)详细说明($$)textarea($$)($$)详细说明($$)' + D.detail
        ];

        for (var z in BIAO) {
            html += jsfrom(BIAO[z]);
        }

        html += jsfrom('ff' + $class + '($$)($$)submit($$)($$)layer.close(OPID);Kuo[\'apijson/admin_request\'].init()($$)提交($$)tijiao');
        html += "</form>";
        OPID = layer.open({
            type: 1,
            zIndex: 10000,
            title: title,
            area: ['100%', '100%'],
            fixed: true,
            maxmin: true,
            content: html,
            success: function (layero, index) {
            }
        });

        layui.form.on('submit(ff' + $class + ')', function (formdata) {
            formdata = formdata.field;
            formdata.Format = 'json';


            apptongxin(Kuo['apijson/admin_request'].url + TOKEN + FENGE + diercai, formdata, function (data) {
                if (data.token && data.token != "") {
                    TOKEN = data.token;
                }
                if (data.code == 99) {
                    layer.close(OPID);
                    layer.msg("请登陆", {
                        offset: 'c',
                        time: 2000
                    }, function () {
                        loadjs("home");
                    });
                } else if (data.code == 1) {

                    if (diercai == "put") {
                        OBJ.update(data.data);
                        layer.close(OPID);
                    } else {
                        Kuo['apijson/admin_request'].get();
                        layer.close(OPID);
                    }

                } else {

                    layer.msg(data.msg, {
                        zIndex: 99999,
                        offset: 'c',
                        time: 2000
                    });
                }
            });
            return false;
        });


        layui.form.render();

    }, del(OBJ) {
        var fromdata = {
            Format: 'json',
            id: OBJ.data.id
        };
        apptongxin(Kuo['apijson/admin_request'].url + TOKEN + FENGE + 'del', fromdata, function (data) {
            if (data.token && data.token != "") {
                TOKEN = data.token;
            }
            if (data.code == 99) {
                layer.msg("请登陆", {
                    offset: 'c',
                    time: 2000
                }, function () {
                    loadjs("home");
                });
            } else if (data.code == 1) {
                OBJ.del();
            } else {
                layer.msg(data.msg, {
                    zIndex: 99999,
                    offset: 'c',
                    time: 2000
                });
            }
        });

    }, CHUUSER(data) {

        let htmls = "";
        let zuhes = [];
        try {
            zuhes = JSON.parse(data);
        } catch (error) { }
        if (zuhes) {
            for (let mx in zuhes) {
                let mx_ = zuhes[mx];
                htmls += '' + Kuo['apijson/admin_request'].$grade[mx_] + '<br/>';
            }
        }
        return htmls;

    }, TABLEADD() {
        let ID = '#' + $class + 'x_structure tbody';
        let html = ``;

        let m = Kuo['apijson/admin_request'].LEIJIA++;

        html += '<tr class="chulis' + m + '">';
        html += `<td><input type="text" class="layui-input" name="structure[` + m + `][n]" placeholder="表单名字"  value=""></td>`;

        html += `<td><input type="text" class="layui-input" name="structure[` + m + `][z]" value="" placeholder="数据库字段名可为空"></td>`;


        html += `<td><select name="structure[` + m + `][b]" >
            <option value="0" selected >选填</option>
            <option value="1">必填</option></select></td>`;



        html += `<td> <div><div class="layui-input-inline"  style="width:70%;"><input type="text" class="layui-input BIAODAN" name="structure[` + m + `][g]" placeholder="验证规则"  value=""></div> <div class="layui-input-inline" style="width:0%;"> 
            <button type="button" class="layui-btn" onclick="Kuo['apijson/admin_request'].TABLEYANZHENG(`+ m + `)"  >选择验证</button></div></td>`;

        html += `<td> <div class="layui-inline"><div class="layui-input-inline " style="width:70%;"><input type="text" class="layui-input HANSHU" name="structure[` + m + `][c]" placeholder="函数处理"  value=""></div> <div class="layui-input-inline" style="width:0%;"> 
            <button type="button" class="layui-btn  layui-bg-blue"  onclick="Kuo['apijson/admin_request'].TABLEHANSHU(`+ m + `)" >选择函数</button></div></td>`;



        html += `<td> <button type="button" onclick="Kuo['apijson/admin_request'].TABLEDEL(` + m + `)"  class="layui-btn layui-bg-red" >删除</button></td>`;

        html += '</tr>';

        $(ID).append(html);

        layui.form.render("select");

    }, TABLEHANSHU(idd) {

        let ID = '#' + $class + 'x_structure .chulis' + idd + ' .HANSHU';
        let opid = 0;

        Kuo['apijson/admin_request'].TABLEHANSHU_ = function (zhis) {

            $(ID).val(zhis);
            layer.close(opid);
        }

        let htmls = `<div style="max-height:650px;overflow: hidden; overflow-y: auto;"><div class="layui-row layui-col-space12">
        <div class="layui-col-xs12">
        自定义函数 val代表表单值 : 分开传递参数 #链接表单名字<br />
        函数名字:val:参数1:#表单名字 </div>`;
        htmls += `<div class="layui-col-xs4"><button type="button" onclick="Kuo['apijson/admin_request'].TABLEHANSHU_('')"  class="layui-btn layui-bg-red" style="width:100%;padding:0px 5px;">清空函数</button></div>`;
        for (var m in Kuo['apijson/admin_request'].$HANSHU) {

            let zhis = Kuo['apijson/admin_request'].$HANSHU[m];

            htmls += `<div class="layui-col-xs4"><button type="button" onclick="Kuo['apijson/admin_request'].TABLEHANSHU_('` + m + `')"  class="layui-btn layui-bg-blue" style="width:100%;padding:0px 5px;">` + zhis + `</button></div>`;
        }

        htmls += `</div></div>`;
        opid = layer.open({
            type: 1,
            area: '60vw',
            resize: false,
            shadeClose: true,
            title: '选择处理函数',
            content: htmls,
            success: function () {



            }
        });



    }, TABLEYANZHENG(idd) {

        let ID = '#' + $class + 'x_structure .chulis' + idd + ' .BIAODAN';

        let opid = 0;

        Kuo['apijson/admin_request'].TABLEYANZHENG_ = function (zhis) {

            $(ID).val(zhis);
            layer.close(opid);
        }

        let htmls = `<div style="max-height:650px;overflow: hidden; overflow-y: auto;"><div class="layui-row layui-col-space12">
        <div class="layui-col-xs12">
        长度验证: 10 十位数 , 10-30 10-30之间 <br />
        函数验证: 函数:函数的名字</div>
        `;


        htmls += `<div class="layui-col-xs4"><button type="button" onclick="Kuo['apijson/admin_request'].TABLEYANZHENG_('')" style="width:100%;"  class="layui-btn layui-bg-red" >清空规则</button></div>`;

        for (var m in Kuo['apijson/admin_request'].$BIAODAN) {

            let zhis = Kuo['apijson/admin_request'].$BIAODAN[m];

            htmls += `<div class="layui-col-xs4"><button type="button" style="width:100%;" onclick="Kuo['apijson/admin_request'].TABLEYANZHENG_('` + m + `')"  class="layui-btn " >` + zhis + `</button></div>`;
        }

        htmls += `</div></div>`;
        opid = layer.open({
            type: 1,
            area: '60vw',
            resize: false,
            shadeClose: true,
            title: '选择验证规则',
            content: htmls,
            success: function () {



            }
        });





    }, TABLEDEL(idd) {

        let ID = '#' + $class + 'x_structure .chulis' + idd;

        layer.confirm('真的要删除吗?', function (index) {
            $(ID).remove();
            layer.close(index);
        });



    },
    add() {
        Kuo['apijson/admin_request'].edit(
            {
                data:
                    { "id": 0, "tags": "", "method": "", "structure": "", "detail": "", "atime": "0", "off": "2" }
            },
            'add');

    },
    get() {

        $("#LAY_app_body ." + $class).html('<style> .' + $class + ' .qfys0{color:#FF5722;} .' + $class + ' .qfys1{color:#009688;}.' + $class + ' .qfys2{color:green;}.' + $class + ' .qfys3{color:#1E9FFF;}</style><div class="layui-fluid"><div class="layui-card"><div class="layui-card-body" style="padding: 15px;">'
            +
            '<div class="' + $class + 'saixuan" style="display:none;margin-bottom:8px;"><form name="form" class="layui-form"><div class="layui-inline" style="width:108px;"> <select name="so_off" class="so_var"></select> </div> <div class="layui-inline" style="width:128px;"> <input class="layui-input so_var" name="so_tags" autocomplete="off" placeholder="Tags"> </div>    <button class="layui-btn" lay-event="sousuo" lay-submit lay-filter="tijiao' + $class + '">搜索</button></form> </div>'
            +
            '<table class="layui-hide" id="apijson' + $class + '" lay-filter="apijson' + $class + '"></table></div></div></div>');
        layui.table.render({
            elem: '#apijson' + $class,
            url: Kuo['apijson/admin_request'].url + TOKEN + FENGE + 'get',
            toolbar: '<div><a class="layui-btn layui-btn-normal" lay-event="add"><i class="layui-icon layui-icon-addition"></i>新增</a> <a class="layui-btn " lay-event="refresh"><i class="layui-icon layui-icon-refresh-3"></i> 刷新</a> <a class="layui-btn layui-btn-danger" lay-event="saixuan"><i class="layui-icon layui-icon-search"></i>筛选</a> </div>',
            cols: [
                [{
                    field: 'id',
                    title: 'ID',
                    width: 88,
                }, {
                    field: "tags",
                    title: "Tags名字"

                }, {
                    field: "method",
                    title: "操作类型"

                }, {
                    field: "off",
                    title: "状态",
                    width: 108,
                    templet: function (d) {
                        return Kuo['apijson/admin_request'].OFF[d.off];
                    }
                }, {
                    field: "atime",
                    title: "时间",
                    width: 188,
                    templet: function (d) {

                        return time(d.atime);
                    }
                }, {


                    title: '操作',
                    width: 158,
                    templet: function (d) {
                        return '<a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>';
                    }
                }]
            ],
            limit: 20,
            page: true,
            done: function (data, curr, count) {
                if (data.token && data.token != "") {
                    TOKEN = data.token;
                }

                if (data.$BIAODAN) {
                    let $BIAODAN = {};
                    for (let m in data.$BIAODAN) {
                        let data_ = data.$BIAODAN[m];
                        let jixi = data_.split('@');
                        $BIAODAN[(jixi[0].trim())] = jixi[1].trim();
                    }
                    Kuo['apijson/admin_request'].$BIAODAN = $BIAODAN;
                }

                if (data.$OFF) {
                    Kuo['apijson/admin_request'].OFF = data.$OFF;
                }

                if (data.$HANSHU) {
                    let $HANSHU = {};
                    for (let m in data.$HANSHU) {
                        let data_ = data.$HANSHU[m];
                        let jixi = data_.split('@');
                        $HANSHU[(jixi[0].trim())] = jixi[1].trim();
                    }
                    Kuo['apijson/admin_request'].$HANSHU = $HANSHU;
                }


            }
        });
        layui.table.on('toolbar(apijson' + $class + ')', function (obj) {
            if (obj.event === 'add') {
                Kuo['apijson/admin_request'].add();
            } else if (obj.event === 'refresh') {
                layer.closeAll();
                Kuo['apijson/admin_request'].init();
            } else if (obj.event === 'saixuan') {
                $("." + $class + "saixuan").toggle();
            }
        });

        layui.table.on('tool(apijson' + $class + ')', function (obj) {
            if (obj.event === 'del') {
                layer.confirm('真的要删除吗?', function (index) {
                    Kuo['apijson/admin_request'].del(obj);
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                Kuo['apijson/admin_request'].edit(obj);
            }

        });

        layui.form.on('submit(tijiao' + $class + ')', function (formdata) {
            formdata = formdata.field;
            var zuhesou = {};
            $('.' + $class + 'saixuan .so_var').each(function (i, v) {
                if ($(v).val() != "") {
                    zuhesou[$(v).attr('name').replace('so_', '')] = $(v).val();
                }
            });
            layui.table.reload('apijson' + $class, {
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                url: Kuo['apijson/admin_request'].url + TOKEN + FENGE + 'get',
                where: zuhesou
            });
            return false;
        });

        layui.table.render();
    }
}
Kuo['apijson/admin_request'].init();